<template>
  <div class="body-login">
    <el-form :model="loginForm" class="login-container">
      <h1>欢迎登入</h1>
      <el-form-item>
        <el-input type="text" placeholder="请输入账号"
                  v-model.trim.lazy="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input type="password" placeholder="请输入密码"
                  v-model.trim.lazy="loginForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click.stop="handleLogin">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import type { LoginInfo } from '@/assets/type/commonType'
import { getMenu } from '@/api/mock/api'
import { userLoginStore } from '@/store/userLogin'
import { useRouter } from 'vue-router'
import RouterNames from '@/router/routerNames'

const loginForm = reactive<LoginInfo>({
  username: '',
  password: ''
})
const router = useRouter()
const loginStore = userLoginStore()
const handleLogin = async () => {
  const response = await getMenu(loginForm)
  loginStore.updateMenuList(response.data.menuList)
  loginStore.token = response.data.token
  loginStore.addRouter(router)
  await router.push({name: RouterNames.home})
}

</script>

<style lang="less" scoped>
.body-login{
  width: 100%;
  height: 100%;
  background-image: url("@/assets/images/background.png");
  background-size: 100%;
  overflow: hidden;
  .login-container{
    width: 400px;
    background-color: #fff;
    border: 1px solid #eaeaea;
    border-radius: 15px;
    padding: 35px 35px 15px 35px;
    box-shadow: 0 0 25px #cacaca;
    margin: 250px auto;

    h1{
      text-align: center;
      margin-bottom: 20px;
      color: #505450;
    }
    :deep(.el-form-item__content){
      justify-content: center !important;
    }
  }
}
</style>